home *** CD-ROM | disk | FTP | other *** search
/ CrystalVision Software Se… Wiki Wonder - Wikipedia / CrystalVision Software Services 703: The Wiki Wonder - Wikipedia.iso / 0703 / Business / CodeX Apps / CodeX.exe / CodeX / html / iSpace / Preview.js < prev    next >
Encoding:
JavaScript  |  2006-09-23  |  7.7 KB  |  255 lines

  1. /*
  2.    This file contains functions to generate OBJECT and EMBED tags for QuickTime content. 
  3.    These functions assemble the tags from parameters passed to them as parameters.
  4.  
  5.     QT_WriteOBJECT()              - generate HTML tags and insert them into the calling document
  6.     QT_WriteOBJECT_XHTML()        - generate XHTML tags and insert them into the calling document
  7.  
  8.     QT_GenerateOBJECTText()       - generate HTML tags and return them as a string
  9.     QT_GenerateOBJECTText_XHTML() - generate XHTML tags and return them as a string
  10.     
  11.     AC_QuickTimeVersion()         - return the version of this file as a floating point number.
  12.  
  13.    To call one of these functions, pass the url, width, height, and required ActiveX
  14.    control version as parameters 1 through 4, and pass all other attributes and 
  15.    parameters that you would otherwise specify for the OBJECT, PARAM, and EMBED 
  16.    tags as pairs of parameters:
  17.  
  18.    <script language="JavaScript" type="text/javascript">
  19.       QT_WriteOBJECT(srcURL, width, height, activeXVersion,
  20.          "attributeName1", "attributeValue1",
  21.          "attributeName1", "attributeValue2",
  22.          "attributeName1", "attributeValue3",
  23.          "attributeName1", "attributeValue4",
  24.          ...
  25.          "attributeNameN", "attributeValueN"
  26.       );
  27.     </script>
  28.  
  29.    These functions automatically add the "classid", "codebase", and "pluginspage" tags to 
  30.    the OBJECT and/or EMBED tags with standard values if they are not specified in the
  31.    parameter list, so you need not supply these tags unless you require non-standard values.
  32.    
  33.    Although the OBJECT and EMBED tags typically have the same attributes and parameters, it
  34.    is sometimes useful to have different values for each. 
  35.    Any attribute name prefixed with "obj#" is added to the OBJECT tag only, any attribute 
  36.    name prefixed with "emb#" is added to the EMBED tag only.
  37.  
  38.    <script language="JavaScript" type="text/javascript">
  39.       QT_WriteOBJECT('http://www.domain.com/sample.mov', '480', '288', ''
  40.         , 'emb#bgcolor', '#FFFFFF');
  41.    </script>
  42.  
  43.  */
  44.  
  45. /************** LOCALIZABLE GLOBAL VARIABLES ****************/
  46.  
  47. var gArgCountErr =    'The "%%" function requires an even number of arguments.'
  48.                 +    '\nArguments should be in the form "atttributeName", "attributeValue", ...';
  49.  
  50. /******************** END LOCALIZABLE **********************/
  51.  
  52. var gTagAttrs                = null;
  53. var gQTGeneratorVersion        = 0.8;
  54.  
  55. function AC_QuickTimeVersion()    { return gQTGeneratorVersion; }
  56.  
  57. function _QTComplain(callingFcnName, errMsg)
  58. {
  59.     errMsg = errMsg.replace("%%", callingFcnName);
  60.     alert(errMsg);
  61. }
  62.  
  63. function _QTAddAttribute(prefix, slotName, tagName)
  64. {
  65.     var        value;
  66.  
  67.     value = gTagAttrs[prefix + slotName];
  68.     if ( null == value )
  69.         value = gTagAttrs[slotName];
  70.  
  71.     if ( null != value )
  72.     {
  73.         if ( 0 == slotName.indexOf(prefix) && (null == tagName) )
  74.             tagName = slotName.substring(prefix.length); 
  75.         if ( null == tagName ) 
  76.             tagName = slotName;
  77.         return tagName + '="' + value + '" ';
  78.     }
  79.     else
  80.         return "";
  81. }
  82.  
  83. function _QTAddObjectAttr(slotName, tagName)
  84. {
  85.     // don't bother if it is only for the embed tag
  86.     if ( 0 == slotName.indexOf("emb#") )
  87.         return "";
  88.  
  89.     if ( 0 == slotName.indexOf("obj#") && (null == tagName) )
  90.         tagName = slotName.substring(4); 
  91.  
  92.     return _QTAddAttribute("obj#", slotName, tagName);
  93. }
  94.  
  95. function _QTAddEmbedAttr(slotName, tagName)
  96. {
  97.     // don't bother if it is only for the object tag
  98.     if ( 0 == slotName.indexOf("obj#") )
  99.         return "";
  100.  
  101.     if ( 0 == slotName.indexOf("emb#") && (null == tagName) )
  102.         tagName = slotName.substring(4); 
  103.  
  104.     return _QTAddAttribute("emb#", slotName, tagName);
  105. }
  106.  
  107.  
  108. function _QTAddObjectParam(slotName, generateXHTML)
  109. {
  110.     var        paramValue;
  111.     var        paramStr = "";
  112.     var        endTagChar = (generateXHTML) ? ' />' : '>';
  113.  
  114.     if ( -1 == slotName.indexOf("emb#") )
  115.     {
  116.         // look for the OBJECT-only param first. if there is none, look for a generic one
  117.         paramValue = gTagAttrs["obj#" + slotName];
  118.         if ( null == paramValue )
  119.             paramValue = gTagAttrs[slotName];
  120.  
  121.         if ( 0 == slotName.indexOf("obj#") )
  122.             slotName = slotName.substring(4); 
  123.     
  124.         if ( null != paramValue )
  125.             paramStr = '  <param name="' + slotName + '" value="' + paramValue + '"' + endTagChar + '\n';
  126.     }
  127.  
  128.     return paramStr;
  129. }
  130.  
  131. function _QTDeleteTagAttrs()
  132. {
  133.     for ( var ndx = 0; ndx < arguments.length; ndx++ )
  134.     {
  135.         var attrName = arguments[ndx];
  136.         delete gTagAttrs[attrName];
  137.         delete gTagAttrs["emb#" + attrName];
  138.         delete gTagAttrs["obj#" + attrName];
  139.     }
  140. }
  141.  
  142.         
  143.  
  144. // generate an embed and object tag, return as a string
  145. function _QTGenerate(callingFcnName, generateXHTML, args)
  146. {
  147.     // is the number of optional arguments even?
  148.     if ( args.length < 4 || (0 != (args.length % 2)) )
  149.     {
  150.         _QTComplain(callingFcnName, gArgCountErr);
  151.         return "";
  152.     }
  153.     
  154.     // allocate an array, fill in the required attributes with fixed place params and defaults
  155.     gTagAttrs = new Array();
  156.     gTagAttrs["src"] = args[0];
  157.     gTagAttrs["width"] = args[1];
  158.     gTagAttrs["height"] = args[2];
  159.     gTagAttrs["classid"] = "clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B";
  160.     gTagAttrs["pluginspage"] = "http://www.apple.com/quicktime/download/";
  161.  
  162.     // set up codebase attribute with specified or default version before parsing args so
  163.     //  anything passed in will override
  164.     var activexVers = args[3]
  165.     if ( (null == activexVers) || ("" == activexVers) )
  166.         activexVers = "6,0,2,0";
  167.     gTagAttrs["codebase"] = "http://www.apple.com/qtactivex/qtplugin.cab#version=" + activexVers;
  168.  
  169.     var    attrName,
  170.         attrValue;
  171.  
  172.     // add all of the optional attributes to the array
  173.     for ( var ndx = 4; ndx < args.length; ndx += 2)
  174.     {
  175.         attrName = args[ndx].toLowerCase();
  176.         attrValue = args[ndx + 1];
  177.  
  178.         // "name" and "id" should have the same value, the former goes in the embed and the later goes in
  179.         //  the object. use one array slot 
  180.         if ( "name" == attrName || "id" == attrName )
  181.             gTagAttrs["name"] = attrValue;
  182.  
  183.         else 
  184.             gTagAttrs[attrName] = attrValue;
  185.     }
  186.  
  187.     // init both tags with the required and "special" attributes
  188.     var objTag =  '<object '
  189.                     + _QTAddObjectAttr("classid")
  190.                     + _QTAddObjectAttr("width")
  191.                     + _QTAddObjectAttr("height")
  192.                     + _QTAddObjectAttr("codebase")
  193.                     + _QTAddObjectAttr("name", "id")
  194.                     + _QTAddObjectAttr("tabindex")
  195.                     + _QTAddObjectAttr("hspace")
  196.                     + _QTAddObjectAttr("vspace")
  197.                     + _QTAddObjectAttr("border")
  198.                     + _QTAddObjectAttr("align")
  199.                     + _QTAddObjectAttr("class")
  200.                     + _QTAddObjectAttr("title")
  201.                     + _QTAddObjectAttr("accesskey")
  202.                     + _QTAddObjectAttr("noexternaldata")
  203.                     + '>\n'
  204.                     + _QTAddObjectParam("src", generateXHTML);
  205.     var embedTag = '  <embed '
  206.                     + _QTAddEmbedAttr("src")
  207.                     + _QTAddEmbedAttr("width")
  208.                     + _QTAddEmbedAttr("height")
  209.                     + _QTAddEmbedAttr("pluginspage")
  210.                     + _QTAddEmbedAttr("name")
  211.                     + _QTAddEmbedAttr("align")
  212.                     + _QTAddEmbedAttr("tabindex");
  213.  
  214.     // delete the attributes/params we have already added
  215.     _QTDeleteTagAttrs("src","width","height","pluginspage","classid","codebase","name","tabindex",
  216.                     "hspace","vspace","border","align","noexternaldata","class","title","accesskey");
  217.  
  218.     // and finally, add all of the remaining attributes to the embed and object
  219.     for ( var attrName in gTagAttrs )
  220.     {
  221.         attrValue = gTagAttrs[attrName];
  222.         if ( null != attrValue )
  223.         {
  224.             embedTag += _QTAddEmbedAttr(attrName);
  225.             objTag += _QTAddObjectParam(attrName, generateXHTML);
  226.         }
  227.     } 
  228.  
  229.     // end both tags, we're done
  230.     return objTag + embedTag + '> </em' + 'bed>\n</ob' + 'ject' + '>';
  231. }
  232.  
  233. // return the object/embed as a string
  234. function QT_GenerateOBJECTText()
  235. {
  236.     return _QTGenerate("QT_GenerateOBJECTText", false, arguments);
  237. }
  238.  
  239. function QT_GenerateOBJECTText_XHTML()
  240. {
  241.     return _QTGenerate("QT_GenerateOBJECTText_XHTML", true, arguments);
  242. }
  243.  
  244. function QT_WriteOBJECT()
  245. {
  246.     document.writeln(_QTGenerate("QT_WriteOBJECT", false, arguments));
  247. }
  248.  
  249. function QT_WriteOBJECT_XHTML()
  250. {
  251.     document.writeln(_QTGenerate("QT_WriteOBJECT_XHTML", true, arguments));
  252. }
  253.  
  254.  
  255.